package com.pignest.hotel.definition;

import com.pignest.hotel.beans.Room;

/** 
 * 房间入住状态
 * 空房, 散客, 团队, 时租, 自用, 预订
 * */
public enum RoomLiveStatus {
	
	EMPTY("空房", "white.png")
	, FILLED("入住", "living.png")
//	, TEAM("团队", "i03.gif")
//	, HOURLY("时租", "i04.gif")
//	, SELF_USE("自用", "i05.gif")
//	, BOOKING("预订", "i06.gif")
	;
	
	private String cname;
	private String icon;
	public final static RoomLiveStatus DEFAULT = EMPTY;

	RoomLiveStatus(String cname, String icon){
		this.cname = cname;
		this.icon = icon;
	}
	
	public String getName() {
		return cname;
	}
	
	public String getImage() {
		return icon;
	}
	
	public boolean is(Room room) {
		return room != null && name().equals(room.getLiveStatus());
	}
	
	/////////////////////////////////////////////////////////////////////////////////////
	
	public static RoomLiveStatus getByCName(String cname) {
		RoomLiveStatus[] values = RoomLiveStatus.values();
		for (int i = 0; i < values.length; i++) {
			if (values[i].cname.equals(cname))
				return values[i];
		}
		return DEFAULT;
	}
	
	/** non-exception version of {@link #valueOf(String)} */
	public static RoomLiveStatus valueof(String name) {
		try {
			return RoomLiveStatus.valueOf(name);
		} catch (RuntimeException e) {//IllegalArgumentException, NullPointerException
		}
		return null;
	}
	
	public static String[] getNames() {
		RoomLiveStatus[] values = RoomLiveStatus.values();
		String[] r = new String[values.length];
		for (int i = 0; i < values.length; i++) {
			r[i] = values[i].name();
		}
		return r;
	}
	
	public static String[] getCNames() {
		RoomLiveStatus[] values = RoomLiveStatus.values();
		String[] r = new String[values.length];
		for (int i = 0; i < values.length; i++) {
			r[i] = values[i].cname;
		}
		return r;
	}
}
